package com.adee.java.collection;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * HashMap：
 *      key和value均可为null
 *      hash(null) = 0
 *      put入链表时采用尾插法
 * ConcurrentHashMap：
 *      key和value都不能为null，否则抛npe
 *
 */
public class Test003_Map {
    public static void main(String[] args) {
        Map<String,String> map1 = new HashMap<>();
        Map<String,String> map2 = new ConcurrentHashMap<>();
        map1.put(null, "hello");
        map1.put("name", null);
        System.out.println(map1.get(null));
        System.out.println(map1.get("name"));

        //map2.put("name", null); // npe
        //map2.put(null, "hello"); // npe
        //System.out.println(map2.get(null)); /npe
        System.out.println(map2.get("name"));

        System.out.println("====================");
        Map<Integer,Integer> map3 = new HashMap<>();
        Integer i1 = 1;
        Integer i2 = new Integer(1);
        Integer i3 = Integer.valueOf(1);
        System.out.println(i1 == i2); // false
        System.out.println(i1.equals(i2)); // true
        System.out.println(i1 == i3); // true
        System.out.println(i1 == Integer.valueOf(i2)); // true

        map3.put(1, 1);
        map3.put(new Integer(1), 2);
        map3.put(2,2);
        System.out.println(map3); // {1=2, 2=2}
    }
}
